#include"Data.h"

Data::Data(int year, int month, int day)
{
	_year = year;
	_month = month;
	_day = day;
}
void Data::print()
{
	cout << _year << "/" << _month << "/" << _day << endl;
}
bool Data::operator==(Data cut)
{
	return (*this)._year == cut._year
		&& (*this)._month == cut._month
		&& (*this)._day == cut._day;
}
bool Data::operator<=(Data cut)
{
	if (_year <= cut._year)
	{
		if (_month <= cut._month)
		{
			if (_day <= cut._day)
			{
				return true;
			}
		}
	}
	return false;
}
bool Data::operator>=(Data cut)
{
	return !(*this <= cut);
	/*if (_year >= cut._year)
	{
		if (_month >= cut._month)
		{
			if (_day >= cut._day)
			{
				return true;
			}
		}
	}
	return false;*/
}
bool Data::operator>(Data cut)
{
	if (*this == cut)
	{
		return false;
	}
	return *this >= cut;
}
bool Data::operator<(Data cut)
{
	if (*this == cut)
	{
		return false;
	}
	return *this <= cut;
}
int Monthday(int year,int month)
{
	int monthday[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	if (month == 2 && ((year % 4 == 0) || (year % 100 != 0) && year % 400 == 0))
	{
		monthday[month] = 29;
	}
	return monthday[month];
}
Data& Data::operator+(int cut)
{
	(*this)._day = (*this)._day + cut;
	while ((*this)._day > Monthday((*this)._year,(*this)._month))
	{
		(*this)._day = (*this)._day - Monthday((*this)._year, (*this)._month);
		(*this)._month++;
		if ((*this)._month == 13)
		{
			(*this)._month = 1;
			(*this)._year++;
		}
	}
	return *this;
}
Data& Data::operator-(int cut)
{
	(*this)._day = (*this)._day - cut;
	while ((*this)._day <= 0)
	{
		if ((*this)._month != 0)
		{
			(*this)._day = (*this)._day + Monthday((*this)._year, (*this)._month - 1);
			(*this)._month--;
		}
		else
		{
			(*this)._year--;
			(*this)._month = 12;
		}
	}
	return *this;
}
//Data& Data::operator--()
//{
//
//}
//Data& Data::operator++()
//{
//
//}
//
//int Data::operator-(Data cut)
//{
//
//}


